home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / textedit.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  6KB  |  131 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, GLib, Pango
  5. from quodlibet import qltk
  6. from quodlibet import util
  7. from quodlibet.formats._audio import AudioFile
  8. from quodlibet.parse import XMLFromPattern
  9. from quodlibet.util import connect_obj
  10.  
  11. try:
  12.     import gi
  13.     gi.require_version('GtkSource', '3.0')
  14.     from gi.repository import GtkSource
  15. except (ValueError, ImportError):
  16.     TextView = Gtk.TextView
  17.     TextBuffer = Gtk.TextBuffer
  18.  
  19. TextView = GtkSource.View
  20.  
  21. class TextBuffer(GtkSource.Buffer):
  22.     
  23.     def __init__(self, *args):
  24.         super(TextBuffer, self).__init__(*args)
  25.         self.set_highlight_matching_brackets(False)
  26.         self.set_highlight_syntax(False)
  27.  
  28.     
  29.     def set_text(self, *args):
  30.         self.begin_not_undoable_action()
  31.         super(TextBuffer, self).set_text(*args)
  32.         self.end_not_undoable_action()
  33.  
  34.  
  35.  
  36. class TextEditBox(Gtk.HBox):
  37.     """A simple text editing area with a default value, a revert button,
  38.     and an apply button. The 'buffer' attribute is the text buffer, the
  39.     'apply' attribute is the apply button.
  40.  
  41.     FIXME: Button text should changable (without poking the buttons directly).
  42.     """
  43.     
  44.     def __init__(self, default = ''):
  45.         super(TextEditBox, self).__init__(spacing = 6)
  46.         sw = Gtk.ScrolledWindow()
  47.         sw.set_shadow_type(Gtk.ShadowType.IN)
  48.         sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
  49.         sw.add(TextView(buffer = TextBuffer()))
  50.         self.pack_start(sw, True, True, 0)
  51.         self.buffer = sw.get_child().get_buffer()
  52.         box = Gtk.VBox(spacing = 6)
  53.         rev = Gtk.Button(stock = Gtk.STOCK_REVERT_TO_SAVED)
  54.         app = Gtk.Button(stock = Gtk.STOCK_APPLY)
  55.         box.pack_start(rev, False, True, 0)
  56.         box.pack_start(app, False, True, 0)
  57.         self.pack_start(box, False, True, 0)
  58.         connect_obj(rev, 'clicked', self.buffer.set_text, default)
  59.         self.revert = rev
  60.         self.apply = app
  61.  
  62.     
  63.     def __get_text(self):
  64.         (start, end) = self.buffer.get_bounds()
  65.         return self.buffer.get_text(start, end, True).decode('utf-8')
  66.  
  67.     text = property(__get_text, (lambda s, v: s.buffer.set_text(v, -1)))
  68.  
  69.  
  70. class PatternEditBox(TextEditBox):
  71.     """A TextEditBox that stops the apply button's clicked signal if
  72.     the pattern is invalid. You need to use connect_after to connect to
  73.     it, to get this feature."""
  74.     
  75.     def __init__(self, default = ''):
  76.         super(PatternEditBox, self).__init__(default)
  77.         self.apply.connect('clicked', self._PatternEditBox__check_markup)
  78.  
  79.     
  80.     def __check_markup(self, apply):
  81.         
  82.         try:
  83.             f = AudioFile({
  84.                 '~filename': 'dummy' })
  85.             Pango.parse_markup(XMLFromPattern(self.text) % f, -1, u'\x00')
  86.         except (ValueError, GLib.GError):
  87.             e = None
  88.             qltk.ErrorMessage(self, _('Invalid pattern'), _('The pattern you entered was invalid. Make sure you enter < and > as \\< and \\> and that your tags are balanced.\n\n%s') % util.escape(str(e))).run()
  89.             apply.stop_emission('clicked')
  90.  
  91.         return False
  92.  
  93.  
  94.  
  95. class TextEdit(qltk.UniqueWindow):
  96.     '''A window with a text editing box in it.'''
  97.     Box = TextEditBox
  98.     
  99.     def __init__(self, parent, default = ''):
  100.         if self.is_not_unique():
  101.             return None
  102.         None(TextEdit, self).__init__()
  103.         self.set_title(_('Edit Display'))
  104.         self.set_transient_for(qltk.get_top_parent(parent))
  105.         self.set_border_width(12)
  106.         self.set_default_size(420, 190)
  107.         vbox = Gtk.VBox(spacing = 12)
  108.         close = Gtk.Button(stock = Gtk.STOCK_CLOSE)
  109.         close.connect(('clicked',), (lambda : self.destroy()))
  110.         b = Gtk.HButtonBox()
  111.         b.set_layout(Gtk.ButtonBoxStyle.END)
  112.         b.pack_start(close, True, True, 0)
  113.         self.box = box = self.Box(default)
  114.         vbox.pack_start(box, True, True, 0)
  115.         self.use_header_bar()
  116.         if not self.has_close_button():
  117.             vbox.pack_start(b, False, True, 0)
  118.         self.add(vbox)
  119.         self.apply = box.apply
  120.         self.revert = box.revert
  121.         close.grab_focus()
  122.         self.get_child().show_all()
  123.  
  124.     text = property((lambda s: s.box.text), (lambda s, v: setattr(s.box, 'text', v)))
  125.  
  126.  
  127. class PatternEdit(TextEdit):
  128.     '''A window with a pattern editing box in it.'''
  129.     Box = PatternEditBox
  130.  
  131.